
<%@page import="com.isoft.gsrm2.server.util.CalendarUtils"%>
<%@page import="com.isoft.gsrm2.server.interchange.base.*"%>
<%@page import="com.isoft.gsrm2.server.interchange.bin.InterchangeTrigger"%>
<%@page import="com.isoft.gsrm2.client.shared.YEncPreferenceList"%>
<%@page import="com.isoft.gsrm2.server.domain.generated.YOrganization"%>
<%@page import="com.isoft.gsrm2.server.test.YInterchangeTester"%>
<%@page import="com.isoft.gsrm2.server.queue.YQueueWorkerManager"%>
<%@page import="com.isoft.gsrm2.server.interchange.core.YInterchangeFileReader"%>
<%@page import="com.isoft.gsrm2.server.interchange.listeners.YDefaultMainInterchangeListener"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.isoft.gsrm2.server.domain.generated.YInterchangeConfig"%>
<%@page import="java.util.List"%>
<%@page import="com.isoft.gsrm2.server.util.HibernateUtils"%>
<%
    if( !"localhost".equals( request.getRemoteHost( ) ) && !"127.0.0.1".equals( request.getRemoteHost( ) ) )
    {
%>
You are trying to connect from an invalid address!!!
<%
    return ;
    }

    String key = request.getParameter( "key" ) ;

    System.err.println( "_Triggered via key : " + key + ", on " + CalendarUtils.now( ) ) ;

    //    if( InterchangeTrigger.DIRECT_FILE_INTERCHANGE.equals( key ) )
    //    {
    //        YDatabaseInterchanger.directFileInterchange();
    //    } else
    if( InterchangeTrigger.READ_INTERCHANGE_FILES.equals( key ) )
    {
        // YDatabaseInterchanger.readInterchangeFiles( null ) ; 
        YEDI.readInterchangeFiles( ) ;
    }
    else if( InterchangeTrigger.RUN_QUEUE_THREAD.equals( key ) )
    {
        YQueueWorkerManager.runQueueThread( ) ;
    }
    else if( InterchangeTrigger.RUN_INTERCHANGE_TEST.equals( key ) )
    {
        YInterchangeTester.testAllConfigs( ) ;
    }
    else if( InterchangeTrigger.CHECK_INTERCHANGE_TEST.equals( key ) )
    {
        YInterchangeTester.checkTestResults( ) ;
    }
    // else if( InterchangeTrigger.PROCESS_INTERCHANGE_DB.equals( key ) )
    // {
    //    YDatabaseInterchanger.processInterchangeDb();
    // }
    else if( InterchangeTrigger.PROCESS_INBOUND_EDI.equals( key ) )
    {
        YEDI.processInboundInterchange( ) ;
    }
    else if( InterchangeTrigger.PROCESS_OUTBOUND_EDI.equals( key ) )
    {
        YEDI.processOutboundInterchange( ) ;
    }
    else if( InterchangeTrigger.PROCESS_EDI.equals( key ) )
    {
        try
        {
            YEDI.processInboundInterchange( ) ;
        }
        catch( Throwable t )
        {
            t.printStackTrace( ) ;
        }
        try
        {
            YEDI.processOutboundInterchange( ) ;
        }
        catch( Throwable t )
        {
            t.printStackTrace( ) ;
        }
    }
    else
    {
%>
invalid trigger token!!!
<%
    }
%>